"""
给定一个非负整数 numRows，生成杨辉三角的前 numRows 行

输入: 5
输出:
[
     [1],
    [1,1],
   [1,2,1],
  [1,3,3,1],
 [1,4,6,4,1]
]
"""


class Solution:
    def generate(self, numRows):
        """
        :type numRows: int
        :rtype: List[List[int]]
        """
        def triangles():
            p = [1]
            while True:
                yield p
                p = [1] + [p[i] + p[i + 1] for i in range(len(p) - 1)] + [1]

        n = 0
        res = []
        if numRows == 0: return res
        for t in triangles():
            res.append(t)
            n = n + 1
            if n >= numRows:
                return res


